package com.junzhiit.nengji.shop.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.junzhiit.nengji.shop.bo.ServeTechnicianBO;
import com.junzhiit.nengji.shop.dao.ServeTechnicianDAO;
import com.junzhiit.nengji.shop.model.ServeTechnician;
import com.junzhiit.nengji.shop.model.enums.Is;

@Repository
public class ServeTechnicianDAOImpl extends AbstractBaseDAO<ServeTechnician> implements ServeTechnicianDAO {

	@Override
	public List<ServeTechnicianBO> findById(ServeTechnicianBO serveTechnicianBO) {
		StringBuffer sql = new StringBuffer();
		StatementParameter param = new StatementParameter();
		sql.append("select g.name 'goodsName'");
		sql.append(" from serve_technician st ");
		sql.append(" inner join goods g on g.id = st.goods_id");
		sql.append(" inner join shop_technician t on t.id = st.technician_id");
		sql.append(" where st.shop_id = ? and st.technician_id = ? and st.is_delete = ?");
		
		param.setString(serveTechnicianBO.getShopId());
		param.setString(serveTechnicianBO.getTechnicianId());
		param.setInt(Is.NO.toIntValue());
		return super.queryForList(sql.toString(),ServeTechnicianBO.class, param);
	}

	@Override
	public List<ServeTechnicianBO> findByServeId(String serveId) {
		StringBuffer sql = new StringBuffer();
		sql.append("select t.name 'technician_name',t.id 'technician_id' from serve_technician st");
		sql.append(" inner join goods g on g.id = st.goods_id");
		sql.append(" inner join shop_technician t on t.id = st.technician_id");
		sql.append(" where st.goods_id = ? and st.is_delete = ?");
		StatementParameter param = new StatementParameter();
		
		param.setString(serveId);
		param.setInt(Is.NO.toIntValue());
		
		return super.queryForList(sql.toString(),ServeTechnicianBO.class, param);
	}

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public boolean deleteByGoodsId(String GoodsId) {
		StringBuffer sql = new StringBuffer();
		sql.append("delete from serve_technician where goods_id=?");
		
		StatementParameter params=new StatementParameter();
		params.setString(GoodsId);
		
		return super.updateForBoolean(sql.toString(), params);
	}
}
